package com.sailfish.springbootdemo.dao.db7;

import com.sailfish.springbootdemo.common.DB7TableName;
import com.sailfish.springbootdemo.pojo.db7.TbFlowCompVplAttr;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface TbFlowCompVplAttrDao {
    @Select("<script>" +
            "select " +
            "* " +
            "from " + DB7TableName.TB_FLOW_COMP_VPL_ATTR + " " +
            "where flow_no = #{flowNo} and flow_level = #{flowLevel}" +
            "</script>"
    )
    List<TbFlowCompVplAttr> getTbFlowCompVplAttrByFlowNo(@Param("flowNo") String flowNo,
                                                     @Param("flowLevel") Integer flowLevel);

    @Insert("<script>" +
            "insert into " + DB7TableName.TB_FLOW_COMP_VPL_ATTR + " " +
            "( "+
            "flow_no, " +
            "flow_level, " +
            "create_time, " +
            "create_user, " +
            "manufacturer_type, " +
            "mpn, " +
            "mcode, " +
            "pkg_name, " +
            "coplanarity, " +
            "weight, " +
            "assembly_type, " +
            "body_length, " +
            "body_width, " +
            "body_height, " +
            "body_length_tol_p, " +
            "body_length_tol_n, " +
            "body_width_tol_p, " +
            "body_width_tol_n, " +
            "body_height_tol_p, " +
            "body_height_tol_n, " +
            "standoff, " +
            "pth_diameter_min, " +
            "vpl_creater, " +
            "approver, " +
            "remark, " +
            "is_orientation, " +
            "is_high_step, " +
            "number " +
            ")"+
            "values "+
            "<foreach collection=\"entities\" item=\"entity\" separator=\",\">" +
            "(" +
            "#{entity.flow_no}, " +
            "#{entity.flow_level}, " +
            "#{entity.create_time}, " +
            "#{entity.create_user}, " +
            "#{entity.manufacturer_type}, " +
            "#{entity.mpn}, " +
            "#{entity.mcode}, " +
            "#{entity.pkg_name}, " +
            "#{entity.coplanarity}, " +
            "#{entity.weight}, " +
            "#{entity.assembly_type}, " +
            "#{entity.body_length}, " +
            "#{entity.body_width}, " +
            "#{entity.body_height}, " +
            "#{entity.body_length_tol_p}, " +
            "#{entity.body_length_tol_n}, " +
            "#{entity.body_width_tol_p}, " +
            "#{entity.body_width_tol_n}, " +
            "#{entity.body_height_tol_p}, " +
            "#{entity.body_height_tol_n}, " +
            "#{entity.standoff}, " +
            "#{entity.pth_diameter_min}, " +
            "#{entity.vpl_creater}, " +
            "#{entity.approver}, " +
            "#{entity.remark}, " +
            "#{entity.is_orientation}, " +
            "#{entity.is_high_step}, " +
            "#{entity.number} " +
            ")"+
            "</foreach>"+
            "</script>"
    )
    Integer insertTbFlowCompVplAttrBatch(@Param("entities") List<TbFlowCompVplAttr> entities);

    @Update("<script>" +
            "update " + DB7TableName.TB_FLOW_COMP_VPL_ATTR + " " +
            "set " +
            " <if test='entity.manufacturer_type != null'>manufacturer_type = #{entity.manufacturer_type},</if>" +
            " <if test='entity.mpn != null'>mpn = #{entity.mpn},</if>" +
            " <if test='entity.mcode != null'>mcode = #{entity.mcode},</if>" +
            " <if test='entity.pkg_name != null'>pkg_name = #{entity.pkg_name},</if>" +
            " <if test='entity.coplanarity != null'>coplanarity = #{entity.coplanarity},</if>" +
            " <if test='entity.weight != null'>weight = #{entity.weight},</if>" +
            " <if test='entity.assembly_type != null'>assembly_type = #{entity.assembly_type},</if>" +
            " <if test='entity.body_length != null'>body_length = #{entity.body_length},</if>" +
            " <if test='entity.body_width != null'>body_width = #{entity.body_width},</if>" +
            " <if test='entity.body_height != null'>body_height = #{entity.body_height},</if>" +
            " <if test='entity.body_length_tol_p != null'>body_length_tol_p = #{entity.body_length_tol_p},</if>" +
            " <if test='entity.body_length_tol_n != null'>body_length_tol_n = #{entity.body_length_tol_n},</if>" +
            " <if test='entity.body_width_tol_p != null'>body_width_tol_p = #{entity.body_width_tol_p},</if>" +
            " <if test='entity.body_width_tol_n != null'>body_width_tol_n = #{entity.body_width_tol_n},</if>" +
            " <if test='entity.body_height_tol_p != null'>body_height_tol_p = #{entity.body_height_tol_p},</if>" +
            " <if test='entity.body_height_tol_n != null'>body_height_tol_n = #{entity.body_height_tol_n},</if>" +
            " <if test='entity.standoff != null'>standoff = #{entity.standoff},</if>" +
            " <if test='entity.pth_diameter_min != null'>pth_diameter_min = #{entity.pth_diameter_min},</if>" +
            " <if test='entity.vpl_creater != null'>vpl_creater = #{entity.vpl_creater},</if>" +
            " <if test='entity.approver != null'>approver = #{entity.approver},</if>" +
            " <if test='entity.remark != null'>remark = #{entity.remark},</if>" +
            " <if test='entity.is_orientation != null'>is_orientation = #{entity.is_orientation},</if>" +
            " <if test='entity.is_high_step != null'>is_high_step = #{entity.is_high_step},</if>" +
            " <if test='entity.number != null'>number = #{entity.number},</if>" +
            " update_time = #{entity.update_time}," +
            " update_user = #{entity.update_user} " +
            " where id = #{entity.id}" +
            //"where flow_no = #{entity.flow_no} and flow_level = #{entity.flow_level}" +
            "</script>"
    )
    Integer updateTbFlowCompVplAttr(@Param("entity") TbFlowCompVplAttr entity);

    @Delete("<script>" +
            "delete from " + DB7TableName.TB_FLOW_COMP_VPL_ATTR + " " +
            "where flow_no = #{flowNo} and flow_level = #{flowLevel}" +
            "</script>"
    )
    Integer deleteTbFlowCompVplAttr(@Param("flowNo") String flowNo, @Param("flowLevel") Integer flowLevel);

    @Delete("<script>" +
            "delete from " + DB7TableName.TB_FLOW_COMP_VPL_ATTR + " " +
            "where flow_no = #{flowNo}" +
            "</script>"
    )
    Integer deleteTbFlowCompVplAttrByFlowNo(@Param("flowNo") String flowNo);
}
